package org.electronic.registration.bo;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Time;
import java.util.Date;

/**
 * User: Egor
 * Date: 08.12.11
 */
@Entity(name = "Arm.Record")
@Table(name = "Arm.Record")
@NamedQueries({
        @NamedQuery(name = Record.GET_SCHEDULER_FOR_DOCTOR, query = "from Arm.Record s where s.doctor = ?"),
        @NamedQuery(name = Record.GET_SCHEDULER_FOR_DOCTOR_FROM_DATE,
                query = "from Arm.Record s where s.doctor = ? and s.recordDate >= ?")
})
public class Record implements Serializable {

    public static final String GET_SCHEDULER_FOR_DOCTOR = "GET_SCHEDULERs_FOR_DOCTOR";
    public static final String GET_SCHEDULER_FOR_DOCTOR_FROM_DATE = "GET_SCHEDULER_FOR_DOCTOR_FROM_DATEs";

    @Id
    @GeneratedValue
    private Integer id;

    @ManyToOne
    @JoinColumn(name = "doctor")
    private Doctor doctor;

    @ManyToOne
    @JoinColumn(name = "patient")
    private Patient patient;

    private java.sql.Date recordDate;


    private Time beginningTime;

    private Time endTime;

    public Record() {
    }

    public Record(Integer id, Doctor doctor, Patient patient, java.sql.Date recordDate, Time beginningTime, Time endTime) {
        this.id = id;
        this.doctor = doctor;
        this.patient = patient;
        this.recordDate = recordDate;
        this.beginningTime = beginningTime;
        this.endTime = endTime;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Doctor getDoctor() {
        return doctor;
    }

    public void setDoctor(Doctor doctor) {
        this.doctor = doctor;
    }

    public Patient getPatient() {
        return patient;
    }

    public void setPatient(Patient patient) {
        this.patient = patient;
    }

    public Date getRecordDate() {
        return recordDate;
    }

    public void setRecordDate(Date recordDate) {
        this.recordDate = new java.sql.Date(recordDate.getTime());
        ;
    }

    public Date getBeginningTime() {
        return beginningTime;
    }

    public void setBeginningTime(Time beginningTime) {
        this.beginningTime = beginningTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Time endTime) {
        this.endTime = endTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Record record = (Record) o;

        if (beginningTime != null ? !beginningTime.equals(record.beginningTime) : record.beginningTime != null)
            return false;
        if (recordDate != null ? !recordDate.equals(record.recordDate) : record.recordDate != null) return false;
        if (doctor != null ? !doctor.equals(record.doctor) : record.doctor != null) return false;
        if (endTime != null ? !endTime.equals(record.endTime) : record.endTime != null) return false;
        if (id != null ? !id.equals(record.id) : record.id != null) return false;
        if (patient != null ? !patient.equals(record.patient) : record.patient != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (doctor != null ? doctor.hashCode() : 0);
        result = 31 * result + (patient != null ? patient.hashCode() : 0);
        result = 31 * result + (recordDate != null ? recordDate.hashCode() : 0);
        result = 31 * result + (beginningTime != null ? beginningTime.hashCode() : 0);
        result = 31 * result + (endTime != null ? endTime.hashCode() : 0);
        return result;
    }
}
